//
//  EWPreOrderBottomView.m
//  haveSomethingToEat
//
//  Created by 陈 宁权 on 2017/7/27.
//  Copyright © 2017年 陈 宁权. All rights reserved.
//

#import "EWPreOrderBottomView.h"

@interface EWPreOrderBottomView()
@property (nonatomic,strong) UILabel *totalPrice;
@end

@implementation EWPreOrderBottomView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addChildView];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)addChildView
{
    UILabel *totalLabel = [[UILabel alloc] init];
    totalLabel.text = @"合计";
    totalLabel.font = [UIFont systemFontOfSize:13];
    totalLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:totalLabel];
    
    _totalPrice = [[UILabel alloc] init];
    _totalPrice.textColor = [UIColor redColor];
    _totalPrice.font = [UIFont systemFontOfSize:13];
    _totalPrice.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_totalPrice];
    
    UIButton *preOrderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [preOrderBtn setTitle:@"联系商家预订" forState:UIControlStateNormal];
    [preOrderBtn setBackgroundColor:BASE_COLOR];
    preOrderBtn.titleLabel.textColor = [UIColor whiteColor];
    preOrderBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [preOrderBtn addTarget:self action:@selector(preOrderBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:preOrderBtn];
    
    [totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.centerX.equalTo(self).dividedBy(4).offset(-5);
        make.bottom.equalTo(self);
        make.width.offset(40);
    }];
    
    [preOrderBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.bottom.equalTo(self);
        make.right.equalTo(self);
        make.width.equalTo(self).dividedBy(2);
    }];
    
    [_totalPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(totalLabel);
        make.left.equalTo(totalLabel.mas_right).offset(5);
        make.right.equalTo(preOrderBtn.mas_left).offset(-5);
        make.bottom.equalTo(self);
    }];
    
}

- (void)setPrices:(NSString *)prices
{
    _prices = prices;
    _totalPrice.text = [NSString stringWithFormat:@"¥%@",_prices];
}

- (void)preOrderBtnClicked
{
    _preOrderBtnClick();
}

@end
